home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / gcc / ixemlsrc.lha / ixemul / string / bcopy.c < prev    next >
C/C++ Source or Header  |  1996-03-13  |  3KB  |  96 lines

  1. /*-
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * the Systems Programming Group of the University of Utah Computer
  7.  * Science Department.
  8.  *
  9.  * Redistribution and use in source and binary forms are permitted
  10.  * provided that: (1) source distributions retain this entire copyright
  11.  * notice and comment, and (2) distributions including binaries display
  12.  * the following acknowledgement:  ``This product includes software
  13.  * developed by the University of California, Berkeley and its contributors''
  14.  * in the documentation or other materials provided with the distribution
  15.  * and in all advertising materials mentioning features or use of this
  16.  * software. Neither the name of the University nor the names of its
  17.  * contributors may be used to endorse or promote products derived
  18.  * from this software without specific prior written permission.
  19.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  20.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  21.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  22.  */
  23.  
  24. #include "defs.h"
  25.  
  26. /*
  27.  * This is probably not the best we can do, but it is still 2-10 times
  28.  * faster than the C version in the portable gen directory.
  29.  *
  30.  * Things that might help:
  31.  *    - unroll the longword copy loop (might not be good for a 68020)
  32.  *    - longword align when possible (only on the 68020)
  33.  *    - use nested DBcc instructions or use one and limit size to 64K
  34.  */
  35. ENTRY(bcopy)
  36. asm("
  37.     movl    sp@(12),d1    /* check count */
  38.     jle    bcdone_bcopy    /* <= 0, don't do anything */
  39.     movl    sp@(4),a0    /* src address */
  40.     movl    sp@(8),a1    /* dest address */
  41.     cmpl    a1,a0        /* src after dest? */
  42.     jlt    bcback        /* yes, must copy backwards */
  43.     movl    a0,d0
  44.     btst    #0,d0        /* src address odd? */
  45.     jeq    bcfeven        /* no, skip alignment */
  46.     movb    a0@+,a1@+    /* yes, copy a byte */
  47.     subql    #1,d1        /* adjust count */
  48.     jeq    bcdone_bcopy    /* count 0, all done  */
  49. bcfeven:
  50.     movl    a1,d0
  51.     btst    #0,d0        /* dest address odd? */
  52.     jne    bcfbloop    /* yes, no hope for alignment, copy bytes */
  53.     movl    d1,d0        /* no, both even */
  54.     lsrl    #2,d0        /* convert count to longword count */
  55.     jeq    bcfbloop    /* count 0, skip longword loop */
  56. bcflloop:
  57.     movl    a0@+,a1@+    /* copy a longword */
  58.     subql    #1,d0        /* adjust count */
  59.     jne    bcflloop    /* still more, keep copying */
  60.     andl    #3,d1        /* what remains */
  61.     jeq    bcdone_bcopy    /* nothing, all done */
  62. bcfbloop:
  63.     movb    a0@+,a1@+    /* copy a byte */
  64.     subql    #1,d1        /* adjust count */
  65.     jne    bcfbloop    /* still more, keep going */
  66. bcdone_bcopy:
  67.     rts
  68. bcback:
  69.     addl    d1,a0        /* src pointer to end */
  70.     addl    d1,a1        /* dest pointer to end */
  71.     movl    a0,d0
  72.     btst    #0,d0        /* src address odd? */
  73.     jeq    bcbeven        /* no, skip alignment */
  74.     movb    a0@-,a1@-    /* yes, copy a byte */
  75.     subql    #1,d1        /* adjust count */
  76.     jeq    bcdone_bcopy    /* count 0, all done  */
  77. bcbeven:
  78.     movl    a1,d0
  79.     btst    #0,d0        /* dest address odd? */
  80.     jne    bcbbloop    /* yes, no hope for alignment, copy bytes */
  81.     movl    d1,d0        /* no, both even */
  82.     lsrl    #2,d0        /* convert count to longword count */
  83.     jeq    bcbbloop    /* count 0, skip longword loop */
  84. bcblloop:
  85.     movl    a0@-,a1@-    /* copy a longword */
  86.     subql    #1,d0        /* adjust count */
  87.     jne    bcblloop    /* still more, keep copying */
  88.     andl    #3,d1        /* what remains */
  89.     jeq    bcdone_bcopy    /* nothing, all done */
  90. bcbbloop:
  91.     movb    a0@-,a1@-    /* copy a byte */
  92.     subql    #1,d1        /* adjust count */
  93.     jne    bcbbloop    /* still more, keep going */
  94.     rts
  95. ");
  96.